|
|
|
|
|
|
|
the vector created by the cross-product is given by the right-hand rule. If you hold the fingers of your right hand pointed in the direction of vector A and then curl them toward the direction of vector B, your thumb points in the direction of the new vector. Figure 15.2 shows how the right-hand rule gives the direction of the new vector. |
|
|
|
|
|
|
|
|
For a solid like the cube shown in Figure 15.1, you can use two adjacent edges of a face for the vectors A and B. In that case, the cross-product A × B is a surface normal. Because you are going to use the normal for backface removal, you must be sure that the normal you pick is the outward-pointing normal. Otherwise, you will not know whether the viewing direction would make an angle greater or less than 90 degrees with the normal to a backface. |
|
|
|
|
|
|
|
|
To ensure that the cross-product always gives you an outward-pointing normal, you can arrange the points that make up each face so that they are listed in a counterclockwise direction, as seen from outside the solid. Then you can use the first three points in the surface to compute the vectors A and B, and the cross-product will give you an outward-pointing normal. This orientation of a surface's data points is called the surface's outward orientation. Figure 15.3 shows how you can use the cross-product of two adjacent edges to find a surface normal for a face on a cube. |
|
|
|
|
|
|
|
|
Testing Angles with Normals |
|
|
|
|
|
|
|
|
Now that you know how to find a surface normal vector, you need to use it to determine whether the viewing direction makes an angle greater than, less than, or equal to 90 degrees with the surface normal. Vector dot products make this test easy. |
|
|
|
|
|
|
|
|
Suppose two vectors A and B have components <x1, y1, z1> and <x2, y2, z2>. The dot product of the two vectors, written "A B," is given by the equation: |
|
|
|
 |
|
|
|
|
A B = x1 * x2 + y1 * y2 + z1 * z2 |
|
|
|
|
|
|
|
|
Let |A| and |B| represent the lengths of the vectors A and B. Let q be the angle between them, as shown in Figure 15.2. Then the dot product of the vectors equals |A| * |B| * Cos(q). You can use this fact to easily determine whether the viewing direction and the surface normal make an angle less than, greater than, or equal to 90 degrees. |
|
|
|
|
|
|
|
|
Figure 15.2
The right-hand rule gives the direction
of a cross-product vector. |
|
|
|
|
|